package me.zk.practice1.hw;

import java.util.*;

public class HWBJJ20 {
    static int total;
    static List<int[]> list = new ArrayList<>();
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String s = scanner.nextLine();

        int[] nums = Arrays.stream(s.substring(1,s.length()-1).split(",")).mapToInt(Integer::parseInt).toArray();
        total = Integer.parseInt(scanner.nextLine());
        boolean[] visit = new boolean[nums.length];
        get(0,new ArrayDeque<>(),nums,visit);
        if (list.size() == 0) {
            System.out.println(-1);
        } else {
            Collections.sort(list, new Comparator<int[]>() {
                @Override
                public int compare(int[] o1, int[] o2) {
                    int s1 = o1[0]+o1[1]+o1[2];
                    int s2 = o2[0]+o2[1]+o2[2];
                    return s1-s2;
                }
            });
            int[] res = list.get(0);
            StringBuffer sb = new StringBuffer("[");
            for (int i = 0; i < res.length; i++) {
                sb.append(nums[res[i]]);
                if (i!=res.length-1){
                    sb.append(",");
                }
            }
            sb.append("]");
            System.out.println(sb);
        }


    }

    public static void get(int index, Deque<Integer> deque,int[] nums, boolean[] visit) {
        if (deque.size() == 3) {
            int sum =0;
            for (int t : deque) {
                sum+=t;
            }
            if (sum == total) {
                int[] a = new int[3];
                int j=0;
                for (int i = 0; i < visit.length; i++) {
                    if (visit[i]){
                        a[j] = i;
                        j++;
                    }
                }
                list.add(a);
            }

        } else {
            for (int i = index; i < nums.length; i++) {
                deque.add(nums[i]);
                visit[i] = true;
                get(i+1,deque,nums,visit);
                deque.removeLast();
                visit[i] = false;
            }

        }
    }
}
